import type {
	Project,
	ProjectStatistics,
	CreateProjectParams,
	UpdateProjectParams,
	ProjectListParams,
	ProjectListResponse
} from '@/types/project';
import type { CommonResult } from '@/types/global';
import { http } from '@/utils/http';

// 接口前缀
const API_PREFIX = '/shopmanager/mobile';

/**
 * 获取项目统计信息
 * @returns 项目统计数据
 */
export const getStatisticsAPI = () => {
	return http<ProjectStatistics>({
		url: `${API_PREFIX}/projects/getStatistics`,
		method: 'GET'
	});
};

/**
 * 获取项目列表
 * @param params 查询参数（分页、筛选等）
 * @returns 项目列表数据
 */
export const getListAPI = (params?: ProjectListParams) => {
	return http<ProjectListResponse>({
		url: `${API_PREFIX}/projects/getList`,
		method: 'GET',
		data: params
	});
};

/**
 * 获取项目详情
 * @param id 项目ID
 * @returns 项目详细信息
 */
export const getDetailAPI = (id: number) => {
	return http<Project>({
		url: `${API_PREFIX}/projects/getDetail/${id}`,
		method: 'GET'
	});
};

/**
 * 创建项目
 * @param params 项目信息
 * @returns 创建的项目信息
 */
export const createAPI = (params: CreateProjectParams) => {
	return http<Project>({
		url: `${API_PREFIX}/projects/create`,
		method: 'POST',
		data: params
	});
};

/**
 * 更新项目
 * @param params 更新参数
 * @returns 更新结果
 */
export const updateAPI = (params: UpdateProjectParams) => {
	return http<CommonResult>({
		url: `${API_PREFIX}/projects/update`,
		method: 'POST',
		data: params
	});
};

/**
 * 删除项目
 * @param id 项目ID
 * @returns 删除结果
 */
export const deleteAPI = (id: number) => {
	return http<CommonResult>({
		url: `${API_PREFIX}/projects/delete/${id}`,
		method: 'DELETE'
	});
};

/**
 * 获取最新项目列表
 * @param params 查询参数
 * @returns 最新项目列表（IPage分页对象）
 */
export const getLatestAPI = (params: { page: number; pageSize: number }) => {
	return http<ProjectListResponse>({
		url: `${API_PREFIX}/projects/getLatest`,
		method: 'GET',
		data: params
	});
};
